<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>计算属性的getter和setter</title>
  <script src="../js/vue.min.js"></script>
</head>

<body>
  <div id ="app"> 
    <h2> {{ fullNames }} </h2>
    <h2> {{ firstNames }} </h2>
  </div>

  <script>
   var vm = new Vue({
    el: '#app',
    data: {
      firstName: 'Kobe',
      lastName: 'Bryant'
    },
    computed: {
      // 简写形式，计算属性一般是没有set方法，只读属性的简写形式
      fullNames: function() {
        return this.firstName + ' ' + this.lastName
      },
      // 计算属性的读写属性
      firstNames: {
        set: function(newValue) {
          this.firstName = newValue;
          console.log("打印了set属性方法");
        },
        // get: function() {
        //   return this.firstName;
        // }
        get() {
          return this.firstName;
        }
      }
    },
    methods: {
    }
   });
  </script>
</body>

</html>